<?php
define( '_VALID_MOS', 1 );
require( '../globals.php' );
require( '../configuration.php' );
require_once( '../includes/joomla.php' );
require_once( '../language/english.php' );

#order online product
$id		= intval(mosGetParam($_REQUEST, 'id', 0));
session_start();
session_id();
$session_name = session_id();
if ($id!=0){
	$sql = "select count(*) from #__orderonline where product_id=".$id." and session_name='".$session_name."'";
	$database->setQuery($sql);
	$count = $database->loadResult();
	if ($count==0){
		$sql = "insert into jos_orderonline(product_id,session_name,so_luong) values(".$id.",'".$session_name."',1)";
		mysql_query($sql);
	}else{
		$sql = "select * from #__orderonline where product_id=".$id." and session_name='".$session_name."'";
		$database->setQuery($sql);
		$database->loadObject($row);
		$sql = "update jos_orderonline set so_luong=".(($row->so_luong)+1)." where product_id=".$id." and session_name='".$session_name."'";
		mysql_query($sql);
	}
}
$sql = "select so_luong from #__orderonline where session_name='".$session_name."'";
$database->setQuery($sql);
$rows = $database->loadObjectList();
$total = 0;
for ($i=0; $i<count($rows); $i++){
	$total = $total + $rows[$i]->so_luong;
}
echo "(".$total.")";
//echo $_SESSION['name'];
?>